﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Shop.Model;
using Shop.Framework.Services;

namespace Shop.Framework.Page {
    public class OrdersPage:ViewPage {

        public List<CustomerOrder> CustomerOrders { get; set; }
        public string Label { get; set; }
        public decimal TotalSale { get; set; }
        protected override void OnInit(EventArgs e) {
            CustomerService service = new CustomerService();
            if (ViewData["To"] == null && ViewData["From"] == null)
                Label = "Orders Today";
            else
                Label = "Orders Filtered";
            
            DateTime toDate = ViewData["To"] != null ? Convert.ToDateTime(ViewData["To"]) : Convert.ToDateTime(DateTime.Now.ToShortDateString() + " 12:00:00 AM");
            DateTime fromDate = ViewData["From"] != null ? Convert.ToDateTime(ViewData["From"]) : Convert.ToDateTime(DateTime.Now.ToShortDateString() + " 12:00:00 PM");

            CustomerOrders = service.GetCustomerOrders(toDate, fromDate);

            TotalSale = 0.00m;
            foreach(var t in CustomerOrders){
                TotalSale += t.TotalPrice;
            }
            base.OnInit(e);
        }

    }
}
